import java.util.concurrent.TimeUnit;

public class ControlPanel {
    private static final int PASSWORD_LENGTH = 4;
    private static final int MAX_WRONG_ATTEMPTS = 3;
    private static final int LOCK_TIME_SECONDS = 120;

    private String password;
    private int wrongAttempts;
    private long lockTime;
    private boolean isLocked;

    public ControlPanel(String password) {
        this.password = password;
        this.wrongAttempts = 0;
        this.lockTime = 0;
        this.isLocked = false;
    }

    public void enterPassword(char[] input) {
        if (isLocked) {
            long currentTime = System.currentTimeMillis();
            if (currentTime - lockTime >= LOCK_TIME_SECONDS * 1000) {
                isLocked = false;
                wrongAttempts = 0;
            } else {
                System.out.println("Control panel is locked. Please try again later.");
                return;
            }
        }

        if (input.length!= PASSWORD_LENGTH) {
            System.out.println("Invalid password length. Please enter a " + PASSWORD_LENGTH + "-digit password.");
            return;
        }

        if (checkPassword(input)) {
            System.out.println("Password correct. Entering system function selection.");
            // 进入系统功能选择状态
        } else {
            wrongAttempts++;
            if (wrongAttempts >= MAX_WRONG_ATTEMPTS) {
                isLocked = true;
                lockTime = System.currentTimeMillis();
                System.out.println("Password incorrect. Control panel is locked for " + LOCK_TIME_SECONDS + " seconds.");
            } else {
                System.out.println("Password incorrect. Please try again.");
            }
        }
    }

    private boolean checkPassword(char[] input) {
        String inputPassword = new String(input);
        return inputPassword.equals(password);
    }

    public static void main(String[] args) {
        ControlPanel controlPanel = new ControlPanel("1234");

        // 模拟输入密码
        controlPanel.enterPassword("1234".toCharArray()); // 正确密码
        controlPanel.enterPassword("5678".toCharArray()); // 错误密码
        controlPanel.enterPassword("9012".toCharArray()); // 错误密码
        controlPanel.enterPassword("3456".toCharArray()); // 错误密码，锁定控制面板
        // 等待120秒
        try {
            TimeUnit.SECONDS.sleep(LOCK_TIME_SECONDS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        // 再次输入密码
        controlPanel.enterPassword("1234".toCharArray()); // 正确密码，进入系统功能选择状态
    }
}
